package com.example.travel.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.example.travel.Adapter.MySearchListViewAdapter;
import com.example.travel.R;

import java.util.ArrayList;

public class search_travel_fragment2 extends Fragment {

    @Override
    public View onCreateView( LayoutInflater inflater,  ViewGroup container,  Bundle savedInstanceState) {
        final View view=inflater.inflate(R.layout.search_product,container,false);
        final int[]images={R.drawable.twg, R.drawable.lhs, R.drawable.ls, R.drawable.cc, R.drawable.bmy};
        final String [] name ={"滕王阁","龙虎山","庐山","长城","兵马俑"};
        final String [] price={"A","A+","A","S+","S-"};
        final String [] introduction={"物华天宝，龙光射牛斗之墟；人杰地灵，徐孺下陈蕃之榻。",
                "瀑布斜飞，藤罗倒挂。虎啸时风生谷口，猿啼时版月坠山腰。",
                "不识庐山真面目，只缘身在此山中",
                "不到长城非好汉，是中华人民的骄傲，也是整个人类的骄傲",
                "神采奕奕，栩栩如生"};
//          final ListView listView = view.findViewById(R.id.listView1);
//          listView.setAdapter(new MyListViewAdapter(getContext(),images,name,price,introduction));
//          listView.setTextFilterEnabled(true);
//          SearchView searchView = view.findViewById(R.id.sv);
//          searchView.setIconifiedByDefault(false);
//          searchView.setSubmitButtonEnabled(false);
//          searchView.setQueryHint("请输入你想要查找的商品");
//          searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
//              @Override
//              public boolean onQueryTextSubmit(String query) {
//                  Toast.makeText(getContext(),"您的选择是："+query,Toast.LENGTH_SHORT).show();
//                  return false;
//              }
//
//              @Override
//              public boolean onQueryTextChange(String newText) {
//                  if (TextUtils.isEmpty(newText)){
//                      listView.clearTextFilter();
//                  }else
//                  {
//                      listView.setFilterText(newText);
//                  }
//                  return true;
//              }
//          });
        final EditText editText = view.findViewById(R.id.et1);
        Button button = view.findViewById(R.id.bt1);
        Button bt2= view.findViewById(R.id.bt2);
        button.setOnClickListener(new View.OnClickListener() {

//            String [] name1 =new String[]{"ss",""};
//            int [] images1 = new int[]{R.drawable.fan,R.drawable.computer2};
//            String [] price1 =new String[]{"ss","Ss"};
//            String [] introduction1 =new String[]{"ss","ss"};

            @Override
            public void onClick(View v) {
                ArrayList<String> name1 = new ArrayList<>();
                ArrayList<Integer>images1 =new ArrayList<>();
                ArrayList<String> price1 =new ArrayList<>();
                ArrayList<String> introduction1 = new ArrayList<>();
                String et_text = editText.getText().toString().trim();
//                if (et_text.length()==0){ return;}
//                int j=0;//从第一位循环添加
                for(int i=0; i<name.length;i++) {

                    if (et_text.equals(name[i])) {
                        name1.add(name[i]);
                        images1.add(images[i]);
                        price1.add(price[i]);
                        introduction1.add(introduction[i]);
                    }
                }
                ListView listView = view.findViewById(R.id.listView1);
                MySearchListViewAdapter myListViewAdapter = new MySearchListViewAdapter(getContext(),images1,name1,price1,introduction1);
                listView.setAdapter(myListViewAdapter);

//                name1.clear();
//                images1.clear();
//                price1.clear();
//                introduction1.clear();
            }
        });

        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment FistContactFragment =new FistContactFragment();
                getFragmentManager().beginTransaction().replace(R.id.flconent,FistContactFragment)
                        .commit();
            }
        });
        return view;
    }
}
